<?php

namespace app\agent\controller;

use app\common\controller\Agent;
use app\common\library\Auth;
use fast\Random;
use think\Db;
use think\Validate;

/**
 * 商品管理
 *
 */
class Goods extends Agent
{

    protected $relationSearch = true;
    protected $searchFields = 'goods_name';
    protected $multiFields = 'goods_status';

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Goods');

    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model->where($where)->with('goodsImages')->where(['goods_status'=>1])->order($sort, $order)->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }



}
